<template>
	<base-page class="base-form" title="通知管理" @back="onCancel()" subTitle="发布通知" @subClick="sendMeassge">
		<view class="main-box" style="padding: 0rpx 32rpx">
			<!-- <u-button @click="sendMeassge()">发布通知</u-button> -->
			<!-- 列表组件 -->
			<view class="content-box">
				<!-- <view v-for="(item,index) in tableWidget.dataList" :key="index">
					<uni-card :title="item.title" :extra="item.addrs">
						<view style="display: flex;justify-content: space-between;align-items: center">
							<text class="uni-body" v-html="item.content" style="line-height: 60px;"></text>
						</view>
						<uni-list>
							<uni-list-item :title="'通知时间：'+item.createTime"></uni-list-item>
							<uni-list-item :title="'更新时间：'+item.updateTime"></uni-list-item>
						</uni-list>
						<view v-show="item.professorId && item.isEvaluate != 1" style="margin: 10px 0">
						</view>
					</uni-card>
				</view> -->
				<view v-for="(item,index) in tableWidget.dataList" :key="index">
					<u-card :title="item.title" padding="30" margin="26rpx" :sub-title="item.startTime">
						<view class="content" slot="body">
							<view>
								<view class="u-body-item-title u-line-2" style="white-space: break-spaces">
									{{ item.content }}
								</view>
							</view>
						</view>
						<view slot="foot" style="display: flex;align-items: center;justify-content: space-between;">
							<view>通知班级：{{ item.classInfo.className }}</view></view>
					</u-card>
				</view>
			</view>
		</view>
	</base-page>
</template>

<script>
	import {
		uploadMixin,
		statsDateRangeMixin
	} from "@/utils/mixins";
	import {
		TableWidget
	} from "@/utils/widget.js";
	import {
		CourseInfoController
	} from "@/api";

	export default {
		name: "mobileStudentmyCourse",
		props: {
			subPage: {
				type: [Number, String, Boolean],
				default: 0,
			},
		},
		mixins: [uploadMixin, statsDateRangeMixin],
		data() {
			return {
				codeIMg: '',
				tableWidget: new TableWidget(
					this.loadCourseInfoWidgetData,
					this.loadCourseInfoVerify,
					true
				),
				formFilter: {
					attendClassTimeFilter: undefined,
				},
				formFilterCopy: {
					attendClassTimeFilter: undefined,
				},
				MobileStudentmyCourse: {
					isInit: false,
				},
				// 表格过滤字段
				sortList: [],
			};
		},
		methods: {
			sendMeassge() {
				uni.navigateTo({
					url: '/views/mangePage/sendNotice'
				})
			},
			QRcode(val) {
				const params = {
					studentSignInDto: {
						classId: val.classId,
						courseId: val.id
					},
				};
				CourseInfoController.QRcodecreate(this, params)
					.then((res) => {
						this.codeIMg = res
						this.$refs.popup.open(res)
					})
					.catch((e) => {});
			},
			changeTime(val) {
				const params = {
					filter: {},
				};

				CourseInfoController.getActivityList(this, params)
					.then((res) => {
						this.tableWidget.dataList = res
					})
					.catch((e) => {});
			},
			onCancel() {
				uni.navigateBack();
			},
			onRefresh() {
				// this.$refs.cardList.reset();

			},

			onShow() {
				this.changeTime();
			},
			/**
			 * 重置过滤值
			 */
			resetMobileStudentmyCourse() {
				this.formFilter.attendClassTimeFilter = undefined;
				this.formFilterCopy.attendClassTimeFilter = undefined;
			},
			/**
			 * 重置所有过滤值
			 */
			resetFilter() {
				this.resetMobileStudentmyCourse();
			},
			onReset() {
				this.resetFilter();
				this.onRefresh();
			},
			refreshMobileStudentmyCourse() {
				this.onRefresh();
			},
			/**
			 * 查询列表数据获取函数，返回Promise
			 */
			loadCourseInfoWidgetData(params) {
				if (params == null) params = {};
				params = {
					...params,
				};
				return new Promise((resolve, reject) => {
					CourseInfoController.list(this, params)
						.then((res) => {
							// console.log(res);

							resolve({
								dataList: res.dataList,
								totalCount: res.totalCount,
							});
						})
						.catch((e) => {
							reject(e);
						});
				});
			},
			/**
			 * 查询列表数据获取检测函数，返回true正常获取数据，返回false停止获取数据
			 */
			loadCourseInfoVerify() {
				this.formFilterCopy.attendClassTimeFilter =
					this.formFilter.attendClassTimeFilter;
				return true;
			},
			/**
			 * 排序改变
			 */
			onTableSortChange(sortInfo) {
				this.tableWidget.onSortChange(sortInfo);
				this.onRefresh();
			},
			/**
			 * 获取卡片图片地址
			 */
			getCardImageUrl(row) {
				let params = {
					id: row.id,
					fieldName: "content",
					asImage: true,
				};
				let fileList = this.parseUploadData(row.content, params);
				if (Array.isArray(fileList) && fileList.length > 0) {
					return fileList[0].url;
				}
				return "";
			},
			formInit() {},
		},
		mounted() {
			// 初始化页面数据
			this.formInit();
			this.onRefresh();
		},
	};
</script>

<style scoped>
	.content-box {
		margin: 0 -15px
	}

	.sort-box {
		display: flex;
		flex-direction: row;
		align-items: center;
		justify-content: flex-start;
	}

	.sort-item {
		display: flex;
		flex-direction: row;
		align-items: center;
		justify-content: center;
	}

	.sort-item+.sort-item {
		margin-left: 8px;
	}

	.nav-icon {
		display: inline;
	}

	.nav-icon+.nav-icon {
		margin-left: 5px;
	}

	.text-black {
		width: 70px;
	}
</style>